package jwdt.xadmin.added.service.impl;


import jwdt.common.dao.BaseDao;
import jwdt.xadmin.added.bean.TOpinion;
import jwdt.xadmin.added.service.OpinionManageService;

import com.ezerg.db.ext.PageUtil;
import com.ezerg.util.DateUtil;
public class OpinionManageServiceImpl implements OpinionManageService{
	private BaseDao<TOpinion> baseDao;
	
	public void setBaseDao(BaseDao<TOpinion> baseDao) {
		this.baseDao = baseDao;
	}
	@Override
	public PageUtil doList(PageUtil pu,TOpinion opinion) throws Exception{
		String where = " 1=1";
		String topic = opinion.getTopic();
		String havereply = opinion.getHavereply()==null?"":opinion.getHavereply()+"";
		if(topic !=null && !"".equals(topic)){
			where +=  " and topic like '%" + topic +"%'";
		}
		if(havereply!=null && !"".equals(havereply)){
			where += " and havereply = '"+ havereply + "'";
		}
		String sql = where + " order by havereply asc,replytime desc";
		pu.doList(TOpinion.class,sql);
		//创造json数据对象
		return pu;
	}
	@Override
	public String doAddact(TOpinion obj) throws Exception {
		return baseDao.doAddObj(obj);
	}

	@Override
	public String doEditact(TOpinion obj, int id) throws Exception {
		obj.setReplytime(DateUtil.getDateTime());
		obj.setHavereply(1);
		return baseDao.doUpdateObj(TOpinion.class, id, obj);
	};
	
	@Override
	public String doDelact(int id) throws Exception {
		return baseDao.doDelObj(TOpinion.class, id);
	}

	@Override
	public TOpinion doLoad(int id) throws Exception {
		return baseDao.doLoadObj(TOpinion.class, id);
	}
	@Override
	public String doUpdateState(int id, String result) throws Exception {
		return baseDao.doIntUpdateState(TOpinion.class, "id="+id, result);
	}
}
